package com.yuxi.Dao.Impl;

import java.io.Serializable;
import java.util.List;

import org.apache.catalina.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.yuxi.Dao.UserPositionDao;
import com.yuxi.Entity.CommentRecordBrowse;
import com.yuxi.Entity.Position;
import com.yuxi.Entity.UserPosition;

@Repository
public class UserPositionDaoImpl extends BaseDaoImpl<Serializable, Serializable>  implements UserPositionDao{

	private Logger logger=LoggerFactory.getLogger(UserPositionDaoImpl.class);
	public UserPositionDaoImpl(){
		super(UserPosition.class);
	}
	@Override
	public UserPosition getPosition(Integer id) {
		// TODO Auto-generated method stub
		return (UserPosition) super.get(id);
	}

	@Override
	public UserPosition addUserPosition(UserPosition userPosition) {
		// TODO Auto-generated method stub
		return (UserPosition) addAndReturn(userPosition);
	}

	@Override
	public void deleteUserPosition(UserPosition userPosition) {
		// TODO Auto-generated method stub
		super.delete(userPosition);
	}

	@Override
	public void modifly(UserPosition userPosition) {
		// TODO Auto-generated method stub
		super.update(userPosition);
	}

	@Override
	public List<UserPosition> getPositionByUserId(Integer userId) {
		// TODO Auto-generated method stub
		return super.find("from UserPosition where userId=?", userId);
	}
	@Override
	public Position getPositionByUser(Integer userId) {	
		List rs=super.find(" select new Position(positiontable.id,"
				+ "positiontable.positionName, positiontable.remark"
				+ ") from Position positiontable,UserPosition userposition where "
				+ "userposition.positionId=positiontable.id and userposition.userId=?", userId);
		if(rs!=null&&rs.size()>=1){
			return (Position)rs.get(0);
		}else{
			return null;
		}		
	}

}
